#include<bits/stdc++.h>
using namespace std;
int T;
int n,m,L,V;
int d[200004];
int p[200004];
int cnt;
int v[200004],a[200004];
int P;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--)
    {
        cin>>n>>m>>L>>V;
        cnt=0;
        P=0;
        for(int i=1;i<=n;i++)
        {
            cin>>d[i]>>v[i]>>a[i];

        }
        for(int i=1;i<=m;i++)
        {
            cin>>p[i];
            P=max(P,p[i]);
        }
        sort(p+1,p+1+m);
        for(int i=1;i<=n;i++)
        {
            if(a[i]==0)
            {
                if(v[i]<=V)
                {
                    continue;
                }
                else
                {
                    if(P<d[i])
                    {
                        continue;
                    }
                    cnt++;
                }

            }
            if(a[i]>0)
            {
                if(P<d[i])continue;
                double pq=2*a[i]*(P-d[i])+v[i]*v[i];
                double vs=sqrt(pq);
                double Qv=V;
                if(vs>Qv)
                {

                    cnt++;
                }

            }
            if(a[i]<0)
            {
                int l=1,r=m;
                while(l<r)
                {

                    int mid=l+r>>1;
                    if(p[mid]>=d[i])
                    {

                        r=mid;

                    }
                    else l=mid+1;
                }
                if(2*a[i]*(p[l]-d[i])+v[i]*v[i]<0)
                {
                    a[i]=0;
                    continue;
                }

                double v1=sqrt(2*a[i]*(p[l]-d[i])+v[i]*v[i]);
                double Qv=V;
                if(v1>Qv)
                {
                    cnt++;
                }
                else
                {
                    a[i]=0;
                }


            }

        }

        cout<<cnt<<" ";
        if(cnt==0)
        {
            cout<<m<<endl;
            continue;
        }
        cout<<m-1<<endl;
    }
    return 0;
}
